package com.lf.util;

import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;

import com.tencentcloudapi.ocr.v20181119.OcrClient;

import com.tencentcloudapi.ocr.v20181119.models.GeneralAccurateOCRRequest;
import com.tencentcloudapi.ocr.v20181119.models.GeneralAccurateOCRResponse;

public class GeneralAccurateOCR{

    public static void main(String[] args) {
        parseImage("https://hehe-1253111109.cos.ap-guangzhou.myqcloud.com/myimg/1591955630871wx07a2186501fd38e2.o6zAJs6x2RdQi2Ygg92OSB68_Pfs.aHImqLAWD8Z752d2410fee09fa50fa943882399c5306.jpg");

    }
    public static String parseImage(String ImageUrl) {
        try{

            Credential cred = new Credential("AKIDKPKsPidjXItKch6y85vUByaKAnGWAR8e", "asrdCX6Uff1DDI8h02ez4tAAuObjodDW");

            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("ocr.tencentcloudapi.com");

            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);

            OcrClient client = new OcrClient(cred, "ap-guangzhou", clientProfile);

            String params = "{\"ImageUrl\":\"" +ImageUrl + "\"}";
            GeneralAccurateOCRRequest req = GeneralAccurateOCRRequest.fromJsonString(params, GeneralAccurateOCRRequest.class);

            GeneralAccurateOCRResponse resp = client.GeneralAccurateOCR(req);

            System.out.println(GeneralAccurateOCRRequest.toJsonString(resp));
            return GeneralAccurateOCRRequest.toJsonString(resp);
        } catch (TencentCloudSDKException e) {
            System.out.println(e.toString());
        }

        return null;
    }

}